import requests
from UA_info import UA_list
import random
from bs4 import BeautifulSoup
from bs4.element import SoupStrainer
import my_send


class IPSpider:
    def __init__(self):
        self.url = 'https://www.ipaddress.com/'

    def get(self):
        headers = {'User-Agent': random.choice(UA_list)}
        response = requests.get(url=self.url, headers=headers)
        html = response.text
        self.parse(html)

    @staticmethod
    def parse(html):
        only_a_tag = SoupStrainer('a', class_='ip ipv4')
        BS = BeautifulSoup(html, 'lxml', parse_only=only_a_tag)
        content = BS.get_text()
        my_send.send_mail(content)

    def run(self):
        self.get()


if __name__ == '__main__':
    spider = IPSpider()
    spider.run()
